import request from '@/utils/request';

// 新增合同
export function addContract(data: any) {
  return request({
    url: '/tienchin/contract',
    method: 'post',
    data
  });
}

// 更新合同
export function updateContract(data: any) {
  return request({
    url: '/tienchin/contract',
    method: 'put',
    data
  });
}

// 查询当前用户已提交未审批任务列表
export function getCommittedTaskList(params?: any) {
  return request({
    url: '/tienchin/contract/committed_task',
    method: 'get',
    params
  });
}

// 根据手机号查询合同详情
export function getContractByPhone(phone: string) {
  return request({
    url: `/tienchin/contract/customer/${phone}`,
    method: 'get'
  });
}

// 查询所有待审批合同
export function getUnapproveContractList(params?: any) {
  return request({
    url: '/tienchin/contract/unapprove',
    method: 'get',
    params
  });
}

// 上传合同原件
export function uploadContractFile(data: FormData) {
  return request({
    url: '/tienchin/contract/upload',
    method: 'post',
    data,
    headers: { 'Content-Type': 'multipart/form-data' }
  });
}

// 根据部门id查询该部门下的人员
export function getUsersByDept(deptId: number) {
  return request({
    url: `/tienchin/contract/users/${deptId}`,
    method: 'get'
  });
}

// 根据id查询合同详情
export function getContractDetail(contractId: number) {
  return request({
    url: `/tienchin/contract/views/${contractId}`,
    method: 'get'
  });
}

// 查看合同PDF
export function viewContractPDF(year: string, month: string, day: string, name: string) {
  return request({
    url: `/tienchin/contract/views/${year}/${month}/${day}/${name}`,
    method: 'get',
    responseType: 'blob'
  });
}

// 删除合同原件
export function deleteContractFile(year: string, month: string, day: string, name: string) {
  return request({
    url: `/tienchin/contract/${year}/${month}/${day}/${name}`,
    method: 'delete'
  });
}

// 查询所有已审批合同
export function getApprovedContractList(params?: any) {
  return request({
    url: '/tienchin/contract/approved',
    method: 'get',
    params
  });
}